﻿using Microsoft.EntityFrameworkCore;

// Code scaffolded by EF Core assumes nullable reference types (NRTs) are not used or disabled.
// If you have enabled NRTs for your project, then un-comment the following line:
// #nullable disable

namespace WebApiDemo
{
    public class RegionContext : DbContext
    {
        public RegionContext()
        {
        }

        public RegionContext(DbContextOptions<RegionContext> options)
            : base(options)
        {
        }

        public virtual DbSet<DArea> DArea { get; set; }
        public virtual DbSet<SysLang> SysLang { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                optionsBuilder.UseSqlServer("Data Source=.;Initial Catalog=region;Integrated Security=true");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<DArea>(entity =>
            {
                entity.HasKey(e => e.VcAreaId)
                    .HasName("PK__d_area__1074F76DA0EC26E3");

                entity.ToTable("d_area");

                entity.Property(e => e.VcAreaId)
                    .HasColumnName("vc_area_id")
                    .HasMaxLength(200)
                    .IsUnicode(false);

                entity.Property(e => e.LLevel).HasColumnName("l_level");

                entity.Property(e => e.VcAreaName)
                    .HasColumnName("vc_area_name")
                    .HasMaxLength(200)
                    .IsUnicode(false);
            });

            modelBuilder.Entity<SysLang>(entity =>
            {
                entity.HasKey(e => e.LId)
                    .HasName("PK__sys_lang__A7C7B6F893465D4C");

                entity.ToTable("sys_lang");

                entity.HasIndex(e => new { e.ELangType, e.VcCode, e.EType })
                    .HasName("INDEX_LANG_TYPE_CODE")
                    .IsUnique();

                entity.Property(e => e.LId).HasColumnName("l_id");

                entity.Property(e => e.EIsEdit)
                    .HasColumnName("e_is_edit")
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.ELangType)
                    .HasColumnName("e_lang_type")
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.EType)
                    .HasColumnName("e_type")
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.VcCode)
                    .HasColumnName("vc_code")
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.VcName)
                    .HasColumnName("vc_name")
                    .HasMaxLength(200)
                    .IsUnicode(false);

                entity.Property(e => e.VcRemark)
                    .HasColumnName("vc_remark")
                    .HasMaxLength(4000)
                    .IsUnicode(false);
            });

            base.OnModelCreating(modelBuilder);

           // OnModelCreatingPartial(modelBuilder);
        }

       // partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
